//
//  MV-ViewController.m
//  22-homework-QQMV-ALi
//
//  Created by 王道林 on 16/8/13.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "MV-ViewController.h"
#import "BaseTableView.h"
#import "MV-tableViewCell-one.h"
#import "WHSNetworkParser.h"
#import "RootData-Model.h"
#import "GXCycleImage.h"
@interface MV_ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) RootData_Model *RootData;
@end

@implementation MV_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createData];
    [self createSubview];
}

- (void)createSubview
{
    self.view.backgroundColor = [UIColor whiteColor];
    _tableView = [[BaseTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = NSUnderlineStyleNone;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[MV_tableViewCell_one class] forCellReuseIdentifier:@"MV"];
}

#pragma mark -Data

- (void)createData
{
    [WHSNetworkParser GETWithURL:@"http://i.y.qq.com/v8/fcg-bin/getmv_by_tag?cmd=mv_shows_new&g_tk=5381&uin=0&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=h5&needNewCode=1&_=1470996835294" par:nil success:^(id responseObject) {
//  解析数据
        _RootData = [RootData_Model modelWithDic:responseObject[@"data"]];
        [self createTableHeader];
        [_tableView reloadData];
        
    } filed:^(NSError *error) {
        NSLog(@"失败%@", error);
    }];
}

// 创建tableview的头视图
- (void)createTableHeader
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 3)];
    [self.view addSubview:view];
    // 创建轮播
    GXCycleImage *CycleImageView = [[GXCycleImage alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height * 2 / 3)];
    CycleImageView.arrayImage = [_RootData.mv_show_play mutableCopy];
    [view addSubview:CycleImageView];
    
    // 创建button
    UIButton *buttonList = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonList.frame = CGRectMake(20, view.frame.size.height *2 / 3 , (view.frame.size.width - 100) / 3, view.frame.size.height / 3);
       
    [buttonList setImage:[UIImage imageNamed:@"619E696CDB65F76EEF3BA66950271ACD"] forState:UIControlStateNormal];
    [buttonList setTitle:@"榜单" forState:UIControlStateNormal];
    [buttonList setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    buttonList.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
    [view addSubview:buttonList];
    
    //创建button2
    UIButton *buttonScene = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonScene.frame = CGRectMake(50 + (view.frame.size.width - 100) / 3, view.frame.size.height *2 / 3 , (view.frame.size.width - 100) / 3, view.frame.size.height / 3);
    
    [buttonScene setImage:[UIImage imageNamed:@"AA6E55172F6218D9C548E626F67CD821"] forState:UIControlStateNormal];
    [buttonScene setTitle:@"现场" forState:UIControlStateNormal];
    [buttonScene setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    buttonScene.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
    [view addSubview:buttonScene];

    //创建button3
    UIButton *buttonPin = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonPin.frame = CGRectMake(80 + (view.frame.size.width - 100) * 2 / 3, view.frame.size.height *2 / 3 , (view.frame.size.width - 100) / 3, view.frame.size.height / 3);
    
    [buttonPin setImage:[UIImage imageNamed:@"6FFFFB698B6BADDDC05E90D53C6CF102"] forState:UIControlStateNormal];
    [buttonPin setTitle:@"频道" forState:UIControlStateNormal];
    [buttonPin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    buttonPin.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
    [view addSubview:buttonPin];

    
    _tableView.tableHeaderView = view;
    
}


// 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _RootData.contents.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MV_tableViewCell_one *cell = [tableView dequeueReusableCellWithIdentifier:@"MV" forIndexPath:indexPath];
   List_Model *listmodel = _RootData.contents[indexPath.row];
    cell.listModel = listmodel;
    return cell;
}

// 返回高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 660;
}


























- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
